package com.uyaer.wheel.story
{
	import com.uyaer.wheel.common.Common;
	import com.uyaer.wheel.display.scene.GameInfo;
	import com.uyaer.wheel.display.scene.GameOver;
	import com.uyaer.wheel.display.scene.Guide;
	import com.uyaer.wheel.display.scene.Home;
	import com.uyaer.wheel.display.scene.Loading;
	import com.uyaer.wheel.display.scene.Pause;
	import com.uyaer.wheel.display.widget.Alert;
	import com.uyaer.wheel.menu.Menu;

	/**
	 *剧情 管理各种剧情
	 * @author hc
	 * 
	 */	
	public class Story
	{
		private var loading:Loading;
		private var home:Home;
		private var gameInfo:GameInfo;
		private var pause:Pause;
		private var gameover:GameOver;
		private var alert:Alert;
		private var guide:Guide;
		
		private static var m_instance:Story;
		private var menuContainer:Menu;
		public function Story()
		{
		}
		
		public static function get instance():Story{
			return m_instance ||= new Story();
		}
		
		public function regiest(menu:Menu):void{
			this.menuContainer = menu;
		}
		
		/**
		 *显示加载界面
		 */		
		public function showLoading(callback:Function):Loading{
			if(!loading){
				loading = new Loading();
			}
			Common.stage.addChild(loading);
			loading.callback = callback;
			loading.start();
			return loading;
		}
		/**
		 *刷新加载界面 
		 * @param d
		 * 
		 */		
		public function updateLoading(d:Number):void{
			if(loading){
				loading.update(d);
			}
		}
		/**
		 *隐藏加载界面 
		 */		
		public function hideLoading(callback:Function):void{
			loading.callback = callback;
			loading.stop();
		}
		
		/**
		 *显示加载界面
		 */		
		public function showHome():Home{
			if(!home){
				home = new Home();
			}
			menuContainer.addChildAt(home,0);
			home.start();
			return home;
		}
		/**
		 *隐藏加载界面 
		 */		
		public function hideHome():void{
			if(home){
				home.stop();
				home.removeFromParent();
			}
		}
		
		/**
		 *显示游戏进行中的信息 
		 */		
		public function showGameInfo():GameInfo{
			if(!gameInfo){
				gameInfo = new GameInfo();
			}
			menuContainer.addChildAt(gameInfo,0);
			gameInfo.start();
			return gameInfo;
		}
		
		/**
		 *隐藏加载界面 
		 */		
		public function hideGameInfo():void{
			if(gameInfo){
				gameInfo.stop();
				gameInfo.removeFromParent();
			}
		}
		
		/**
		 *显示暂停界面 
		 * @return 
		 */		
		public function showPause():Pause{
			if(!pause){
				pause = new Pause();
			}
			menuContainer.addChild(pause);
			pause.start();
			return pause;
		}
		
		/**
		 *隐藏暂停界面
		 */		
		public function hidePause():void{
			if(pause){
				pause.stop();
				pause.removeFromParent();
			}
		}
		
		public function showGameOver():void{
			if(!gameover){
				gameover = new GameOver();
			}
			menuContainer.addChild(gameover);
			gameover.start();
		}
		
		public function hideGameOver():void{
			if(gameover){
				gameover.stop();
				gameover.removeFromParent();
			}
		}
		
		/**
		 *显示提示框 
		 * @param txt
		 * @param callback
		 * 
		 */		
		public function showAlert(txt:String,callback:Function):void{
			if(!alert){
				alert = new Alert();
			}
			menuContainer.addChild(alert);
			alert.showYesNo(txt,callback);
		}
		
		public function showGuide():void{
			if(!guide){
				guide = new Guide();
			}
			menuContainer.addChild(guide);
			guide.start();
		}
	}
}